var sendReq = getXmlHttpRequestObject();
    var receiveReq = getXmlHttpRequestObject();
    var lastMessage = 0;
    var mTimer;	

	function startChat() 
	{
	    setTimeout("getChatText()", 1200);
	}

	function getXmlHttpRequestObject() 
	{
		if (window.XMLHttpRequest) 
		{
			return new XMLHttpRequest();
		} 
		else if(window.ActiveXObject) 
		{
			return new ActiveXObject("Microsoft.XMLHTTP");
		} 
		else 
		{
			document.getElementById('p_status').innerHTML = 'Status: Cound not create XmlHttpRequest Object.  Consider upgrading your browser.';
		}
	}

	function getChatText() 
	{
	    if (receiveReq)
	    {
    		if (receiveReq.readyState == 4 || receiveReq.readyState == 0) 
    		{
    		    if (bIsPathTranslated)
    		    {
    		        var sUrlAdd = 'index.php/public/check-im/';
    		    } else 
    		    {
    		        sUrlAdd = 'index.php?' + sGetPathVar + '=' + '/public/check-im/';
    		    }
    			receiveReq.open("GET", SciptHome+sUrlAdd, true);
    			receiveReq.onreadystatechange = handleReceiveChat;
    			receiveReq.send(null);
    		}
	    }
	}

	function handleReceiveChat() 
	{
	    if (receiveReq)
	    {
    		if (receiveReq.readyState == 4 || receiveReq.readyState == 0) 
    		{
    			var chat_div = document.getElementById('div_chat');
    			var xmldoc = receiveReq.responseXML;
    			var message_nodes = xmldoc.getElementsByTagName("message"); 
    			var n_messages = message_nodes.length;
    			for (i = 0; i < n_messages; i++) 
    			{
    				var user_node = message_nodes[i].getElementsByTagName("user");
    				var time_node = message_nodes[i].getElementsByTagName("time");
    				if(user_node[0] != null)
    				{
    					chat_div.innerHTML = '' +user_node[0].firstChild.nodeValue + '';
    					chat_div.scrollTop = chat_div.scrollHeight;
    				}
    				else
    				    chat_div.innerHTML = '';
    				
    				lastMessage = (message_nodes[i].getAttribute('id')) ? (message_nodes[i].getAttribute('id')) : 0;
    			}
    			mTimer = setTimeout('getChatText();',10000);
    		}
	    }
	}